home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 14851 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.1 KB

  1. Path: tech.cftnet.com!not-for-mail
  2. From: wcowley@cftnet.com (Wes Cowley)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Proper use of friend keyword
  5. Date: 2 Apr 1996 10:53:10 GMT
  6. Organization: CFTnet
  7. Message-ID: <4jr0um$ste@tech.cftnet.com>
  8. References: <4jn38u$j9c@holly.ACNS.ColoState.EDU>
  9. NNTP-Posting-Host: ppp250_4.cftnet.com
  10. X-Newsreader: TIN [UNIX 1.3 950824BETA PL0]
  11.  
  12. Corby S. Hudnall (corbyh@holly.ACNS.ColoState.EDU) wrote:
  13. [ ... ]
  14. : class ABC
  15. : {
  16. :     int AValue;
  17. :     int GetAValue() { return (AValue); }
  18. : public:
  19. :     ABC() { AValue=5; }
  20. :     ~ABC(){ }
  21. : };
  22. : class XYZ
  23. : {
  24. : public:
  25. :     XYZ() { }
  26. :     ~XYZ() { }
  27. :     friend int ABC::GetAValue();
  28. : };
  29. [ ... ]  
  30. : when I try to compile this, I get the message "no member funciton 
  31. : 'XYZ::GetAValue()' defined."  What do I need to do in order to 
  32. : make this work.  Thanks for any and all suggestions.
  33.  
  34. It looks like you've got a bit of a misunderstanding of what friend does.
  35. In the classes above, the friend declaration says that ABC's GetAValue()
  36. can access private and protected members of XYZ.  It does not add a
  37. new member function to XYZ.  
  38.  
  39. Wes
  40.